using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Utilities;
using Models.WebSite_HaiSheng;
namespace WebSite_HaiSheng.Controllers
{ 
public class JobApplyController : Controller
{
    public ViewResult Index()
    {
        return View(CH.GetAllData<JobApply>());
    }

    public ActionResult AjaxJobApplyIndex(int recruitmentId)
    {
        return new DataJsonResult<JobApply>() { Data = CH.GetAllData<JobApply>(j => j.RecruitmentID == recruitmentId) };
    }

    public ViewResult Details(int id)
    {
       return View(CH.GetDataById<JobApply>(id));
    }

    //public ActionResult Create(int recruitmentId)
    //{
    //    ViewBag.RecruitmentId = recruitmentId;
    //    return View();
    //}

   [HttpPost]
   public ActionResult Create(JobApply item)
   {
       if (ModelState.IsValid)
       {
             CH.Create<JobApply>(item);
             return RedirectToAction("Index","Recruitment"); 
       }
       return View(item);
   }
   public ActionResult Edit(int id)
   {
       return View(CH.GetDataById<JobApply>(id));
   }

   [HttpPost]
   public ActionResult Edit(JobApply item)
   {
       if (ModelState.IsValid)
       {
            CH.Edit<JobApply>(item);
            return RedirectToAction("Index", "Recruitment"); 
       }
       return View(item);
   }

   public ActionResult Delete(int id)
   {
       return View(CH.GetDataById<JobApply>(id));
   }

   [HttpPost, ActionName("Delete")]
   public ActionResult DeleteConfirmed(int id)
  {
      CH.Delete<JobApply>(id);
      return RedirectToAction("Index", "Recruitment"); 
  }
}
}
